package com.wyk.admin.controller;

import com.wyk.admin.common.convention.result.Result;
import com.wyk.admin.common.convention.result.Results;
import com.wyk.admin.dto.req.GroupSortReqDTO;
import com.wyk.admin.dto.req.GroupUpdateReqDTO;
import com.wyk.admin.dto.req.ShortLinkGroupSavaDTO;
import com.wyk.admin.dto.resp.ShortLinkRespDTO;
import com.wyk.admin.service.GroupService;
import jakarta.annotation.Resource;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 短连接分组控制层
 */
@RestController
public class GroupController {

    @Resource
    private  GroupService groupService;

    /**
     * 添加短连接分组
     * @param shortLinkGroupSavaDTO
     * @return
     */
    @PostMapping("/api/short-link/admin/v1/group")
    public Result<Void> saveGroup(@RequestBody ShortLinkGroupSavaDTO shortLinkGroupSavaDTO) {
        groupService.saveGroup(shortLinkGroupSavaDTO.getName());
        return Results.success();
    }

    /**
     * 修改短连接分组
     * @param groupUpdateReqDTO
     * @return
     */
    @PutMapping("/api/short-link/admin/v1/group")
    public Result<Void> updateGroup(@RequestBody GroupUpdateReqDTO groupUpdateReqDTO) {
        groupService.updateGroup(groupUpdateReqDTO);
        return Results.success();
    }

    /**
     * 删除短链接分组
     * @param gid
     * @return
     */
    @DeleteMapping("/api/short-link/admin/v1/group")
    public Result<Void> deleteGroup(@RequestParam("gid") String gid) {
            groupService.deleteGroup(gid);
        return Results.success();
    }

    /**
     *  查询用户短链接分组集合
     * @return
     */
    @GetMapping("/api/short-link/admin/v1/group")
    public Result<List<ShortLinkRespDTO>> listGroup() {
        return Results.success(groupService.listGroup());
    }

    /**
     * 短连接分组排序
     * @param groupSortReqDTOList
     * @return
     */
    @PostMapping("/api/short-link/admin/v1/group/sort")
    private Result<Void> sortGroup(@RequestBody List<GroupSortReqDTO> groupSortReqDTOList) {
        groupService.sortGroup(groupSortReqDTOList);
        return Results.success();
    }


}